﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Business.DwzFrame;
using NHibernate;
using ZLCMS.Data.Model;
using ZLCMS.Business;

namespace ZLCMS.Web.SystemManage.Basics.Advert
{
    public partial class AdvertDelete : System.Web.UI.Page
    {
        protected FrameHelper _framePage;

        protected void Page_Load(object sender, EventArgs e)
        {
            //初始化DWZ控件
            _framePage = new FrameHelper(this);
            
            //批量删除
            if (Request["ajax"] == "dels")
            {
                String ids = Request["ids"];
                if (!String.IsNullOrEmpty(ids))
                {
                    using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
                    {
                        String[] idArray = ids.Split(',');
                        foreach (String id in idArray)
                        {
                            try
                            {
                                session.Delete(new ShopAdvertInfo() { Id = Int32.Parse(id) });
                            }
                            catch (System.Exception ex)
                            {
                                _framePage.Alert(new ReturnCode() { statusCode = 300, message = "操作失败-" + ex.Message });
                                return;
                            }
                        }
                        session.Flush();
                    }
                }
            }
            //单个删除
            else if (!String.IsNullOrEmpty(Request["uid"]))
            {
                using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
                {
                    try
                    {
                        session.Delete(new ShopAdvertInfo() { Id = Int32.Parse(Request["uid"]) });
                        session.Flush();
                    }
                    catch (System.Exception ex)
                    {
                        _framePage.Alert(new ReturnCode() { statusCode = 300, message = "操作失败-" + ex.Message });
                        return;
                    }
                }
            }
            else
            {
                _framePage.Alert(new ReturnCode() { statusCode = 300, message = "操作失败-参数错误!" });
            }

            _framePage.Alert(new ReturnCode() { statusCode = 200, message = "操作成功!", navTabId = _framePage.NavTabId });
        }
    }
}